﻿function AutoTextArea(textareaNode) {
    if (textareaNode == null)
        return;
    var ie = !!window.attachEvent && !window.opera;
    var ie9 = ie && (!!+"\v1");
    var inputhandler = function (node, fun) {
        if ("oninput" in node) {
            node.oninput = fun;
        } else {
            node.onpropertychange = fun;
        }
        if (ie9) node.onkeyup = fun;
    }

    inputhandler(textareaNode, function () {
        if (!ie) textareaNode.style.height = 40 + "px";
        var height = textareaNode.scrollHeight;
        if (height >= 40) {
            textareaNode.style.height = height + "px";
        } else {
            textareaNode.style.height = 40 + "px";
        }
    });
}

